<html>
<head><meta charset="utf-8"><title>Philosophy of `From` [split from Meeting 2021-04-12] · project-error-handling · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/index.html">project-error-handling</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html">Philosophy of `From` [split from Meeting 2021-04-12]</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="234219998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234219998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234219998">(Apr 12 2021 at 19:54)</a>:</h4>
<p>T implementing TryFrom for an option of itself seems unusual to me</p>



<a name="234220050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234220050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234220050">(Apr 12 2021 at 19:55)</a>:</h4>
<p>but I guess the inner type doesn't need to be T</p>



<a name="234221285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234221285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234221285">(Apr 12 2021 at 20:02)</a>:</h4>
<p>I don't really have a concrete "oh yes I needed it here".  Mostly it's related to my general philosophy that if something's <code>From</code> in one direction should probably be <code>TryFrom</code> (perhaps <code>From</code>) in the other direction.  (And if that's not possible, maybe <code>From</code> wasn't a good idea in the first place.)</p>



<a name="234221412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234221412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234221412">(Apr 12 2021 at 20:03)</a>:</h4>
<p>I see</p>



<a name="234221926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234221926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234221926">(Apr 12 2021 at 20:07)</a>:</h4>
<p>Like <code>.try_into().unwrap()</code> to pull a variant out of a <code>net::IpAddr</code> feels reasonable to me -- it's like a downcast in that it's probably not something you should be doing super often, but...</p>



<a name="234222068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222068">(Apr 12 2021 at 20:08)</a>:</h4>
<p>ah, yea that one makes sense to me</p>



<a name="234222080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222080">(Apr 12 2021 at 20:08)</a>:</h4>
<p>it doesn't feel like a fundamental property to me though</p>



<a name="234222150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222150">(Apr 12 2021 at 20:08)</a>:</h4>
<p>like, I can see constructing something with <code>From</code> as vaguely destructive to the original input</p>



<a name="234222174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222174">(Apr 12 2021 at 20:09)</a>:</h4>
<p>or I guess, potentially destructive</p>



<a name="234222415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222415">(Apr 12 2021 at 20:11)</a>:</h4>
<p>Yeah, I agree it's not impossible -- <code>BinaryHeap&lt;T&gt;: From&lt;Vec&lt;T&gt;&gt;</code> is an existing example.  But at the same time that's one of those that feels like it needs a comment because it's not obvious what it's doing, and thus maybe it should have been <code>.heapify()</code> or something instead of <code>.into()</code>.</p>



<a name="234222492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222492">(Apr 12 2021 at 20:11)</a>:</h4>
<p>ah yea</p>



<a name="234222641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222641">(Apr 12 2021 at 20:12)</a>:</h4>
<p>And in general, there's often multiple reasonable destructive ways to convert something, which pushes it away from <code>From</code>.</p>
<p>But regardless, I look forward to checking in try_trait_v2 and being able to deprecate <code>NoneError</code> and force the conversation to stop <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="234222649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222649">(Apr 12 2021 at 20:12)</a>:</h4>
<p>feels similar to <a href="https://github.com/rust-lang/rust/pull/84111">https://github.com/rust-lang/rust/pull/84111</a> , where <code>impl From&lt;[(K, V); N]&gt; for HashMap</code> loses both the order of the input and any duplicates</p>



<a name="234222652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222652">(Apr 12 2021 at 20:12)</a>:</h4>
<p>I wonder if there are any good writeups on when it is and isn't appropriate to use From</p>



<a name="234222678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222678">(Apr 12 2021 at 20:13)</a>:</h4>
<p>I definitely have seen a few different approaches</p>



<a name="234222733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222733">(Apr 12 2021 at 20:13)</a>:</h4>
<p>specifically, when to use from vs making a constructor method</p>



<a name="234222773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222773">(Apr 12 2021 at 20:13)</a>:</h4>
<p>and managing the boundary between constructors as a trait bound you can rely upon</p>



<a name="234222909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222909">(Apr 12 2021 at 20:14)</a>:</h4>
<p>I always struggle with <code>T::new()</code> vs <code>T::default()</code></p>



<a name="234222942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234222942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234222942">(Apr 12 2021 at 20:14)</a>:</h4>
<p>My "<code>A: From&lt;B&gt;</code> probably only is good if <code>B: TryFrom&lt;A&gt;</code> makes sense too" heuristic came out of conversations in <a href="https://github.com/rust-lang/rfcs/pull/2484">https://github.com/rust-lang/rfcs/pull/2484</a></p>



<a name="234223056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234223056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234223056">(Apr 12 2021 at 20:15)</a>:</h4>
<p>I'll definitely be keeping that heuristic in mind going forward to see how well it applies to my experiences</p>



<a name="234323671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257204-project-error-handling/topic/Philosophy%20of%20%60From%60%20%5Bsplit%20from%20Meeting%202021-04-12%5D/near/234323671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DPC <a href="https://rust-lang.github.io/zulip_archive/stream/257204-project-error-handling/topic/Philosophy.20of.20.60From.60.20.5Bsplit.20from.20Meeting.202021-04-12.5D.html#234323671">(Apr 13 2021 at 13:23)</a>:</h4>
<p>I generally use <code>From&lt;..&gt;</code> for "equal-ish" types. As in, if I have a struct with a member and i'm creating the struct from that member, I would use <code>from_x</code> as a method instead of the <code>From</code> trait</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>